﻿namespace MSSqlSchemaDoc.Core.DataStructures
{
    using System;
    using System.Xml.Serialization;

    /// <summary>
    /// Provides a base for documentable objects.
    /// </summary>
    [Serializable()]
    public class DocumentationObjectBase : IDocumentationObject
    {
        /// <summary>
        /// Gets or sets the type of object represented.
        /// </summary>
        [XmlIgnore()]
        public virtual DataStructureObjectType ObjectType { get; set; }

        /// <summary>
        /// Gets or sets the name of the object.
        /// </summary>
        [XmlAttribute()]
        public string Name { get; set; }

        /// <summary>
        /// Gets or sets the schema of the object (if applicable).
        /// </summary>
        [XmlAttribute()]
        public string Schema { get; set; }

        /// <summary>
        /// Gets or sets the documentation for the object.
        /// </summary>
        [XmlElement()]
        public string Documentation { get; set; }

        /// <summary>
        /// Represents the object as a string.
        /// </summary>
        /// <returns>The name of the object.</returns>
        public override string ToString()
        {
            if (string.IsNullOrEmpty(this.Schema))
            {
                return this.Name;
            }
            else
            {
                return string.Concat(this.Name, "_", this.Schema);
            }
        }
    }
}
